<!--
 * @Author: wjk
 * @Date: 2019-12-31 15:40:51
 * @LastEditors: wjk
 * @LastEditTime: 2019-12-31 15:51:20
 * @description: file content
 -->
<template>
  <base-page-view class-name="page-container">
    <view>
      <view class="list">
        <view v-for="(item, index) in goodsList" :key="index" class="listItem" @click="_toFunctionDetail(item)">
          <image :src="item.pic" mode="widthFix" class="icon-image"></image>
          <view class="title">{{ item.title }}</view>
          <view class="subTitle">{{ item.subtitle }}</view>
        </view>
      </view>
    </view>
  </base-page-view>
</template>
<script>
import { toFunctionDetail } from '@/utils/navigateTo'
import './index.scss'
export default {
  components: {
  },
  data() {
    return {
      listQuery: {
        page_size: 10,
        page_no: 1
      },
      goodsList: [],
      nomore: false
    }
  },
  onPullDownRefresh() {
    this.listQuery.page_no = 1
    this.goodsList = []
    this.nomore = false
    this._getData()
  },
  onReachBottom() {
    if (this.nomore) return
    this.listQuery.page_no += 1
    this._getData()
  },

  created() {
  },
  onLoad() {
    this._getData()
  },
  onShow() {
  },
  methods: {
    async _getData() {
      const res = await this.$api.homeApi.getChoiceness(this.listQuery)
      if (res.code === 0) {
        this.goodsList = this.goodsList.concat(res.data)
        if (res.data.length < 10) {
          this.nomore = true
        }
        setTimeout(function() {
          uni.stopPullDownRefresh()
        }, 500)
      }
    },
    _toFunctionDetail(item) {
      // #ifdef MP-WEIXIN
      uni.setStorageSync('webViewTitle', item.title)
      toFunctionDetail(item)
      // #endif
      // #ifdef H5
      if (item.type_val.indexOf('http') > -1) {
        window.location.href = item.type_val
      }
      // #endif
    }
  }
}
</script>
